<?php
class Train extends MY_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('model_train');
		$this->load->model('model_rate');
    }
    public function findday($orgDate){
	    $strto = strtotime($orgDate);
	    $retDAY = date('Y-m-d', mktime(0,0,0,date('m',$strto),date('d',$strto),date('Y',$strto)));
	    return $retDAY;
	}
    public function detail() {
		$id = $this->uri->segment(2);
		$data['result'] = $this->model_train->getdata($id);
		if($data['result'] == NULL){ redirect(base_url());}
		$now = strtotime(date("m/d/Y"));
	    $tomorow = date('m/d/Y',mktime(0,0,0,date('m',$now),date('d',$now) + 1,date('Y',$now)));
	    $nexttomor = date('m/d/Y',mktime(0,0,0,date('m',$now),date('d',$now) + 2,date('Y',$now)));
	    $curtrain = $data['result'];
	    $curtype = 2;
	    $adults = 1;
	    $data['typetick'] = 2;
	    $curstart = $this->findday($tomorow);
	    $curend = $this->findday($nexttomor);
		//echo $data['result']['train_id']; die();
	    $data['liststart'] = $this->model_rate->getstart($data['result']['train_id'],$curtype,$curstart);
		//$this->debug($data['liststart']);
	    $data['listend'] = $this->model_rate->getstart($data['result']['train_id'],$curtype,$curend);
		$data['trainid'] = $data['result']['train_id'];
		$data['curstart'] = $tomorow;
		$data['curendate'] = $nexttomor;
		$data['adults'] = $adults;
        $data['title'] = $data['result']['train_name']." - Hanoi Sapa Train";
        $this->load->view('train/layout',$data);
    }
}
?>